- name: make the app be real
  hosts: os_control[0]:os_control_stg[0]
  user: root
  gather_facts: False

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml


  roles:
  - role: rabbit/queue
    username: greenwave{{ env_suffix }}
    queue_name: greenwave{{ env_suffix }}
    routing_keys:
      - "org.fedoraproject.*.taskotron.result.new"
      - "org.fedoraproject.*.waiverdb.waiver.new"
    thresholds:
      warning: 50
      critical: 100
    sent_topics: ^org\.fedoraproject\.{{ env_short }}\.greenwave\..*

  # The openshift/project role breaks if the project already exists:
  # https://pagure.io/fedora-infrastructure/issue/6404
  - role: openshift/project
    app: greenwave
    description: greenwave
    appowners:
    - dcallagh
    - gnaponie
    - lholecek
    - ralph
    - cverna
    - pingou
    - vmaljulin
    - lholecek
    tags:
      - apply-appowners

  - role: openshift/secret-file
    app: greenwave
    secret_name: greenwave-fedora-messaging-key
    key: greenwave.key
    privatefile: "rabbitmq/{{env}}/pki/private/greenwave{{env_suffix}}.key"

  - role: openshift/secret-file
    app: greenwave
    secret_name: greenwave-fedora-messaging-crt
    key: greenwave.crt
    privatefile: "rabbitmq/{{env}}/pki/issued/greenwave{{env_suffix}}.crt"

  - role: openshift/secret-file
    app: greenwave
    secret_name: greenwave-fedora-messaging-ca
    key: greenwave.ca
    privatefile: "rabbitmq/{{env}}/pki/ca.crt"

  - role: openshift/object
    app: greenwave
    template: imagestream.yml
    objectname: imagestream.yml

  - role: openshift/object
    app: greenwave
    template: configmap.yml
    objectname: configmap.yml

  - role: openshift/object
    app: greenwave
    file: service.yml
    objectname: service.yml

  - role: openshift/route
    app: greenwave
    routename: web-pretty
    host: "greenwave{{ env_suffix }}.fedoraproject.org"
    serviceport: web
    servicename: greenwave-web

  # TODO -- someday retire this old route in favor of the pretty one above.
  - role: openshift/object
    app: greenwave
    file: route.yml
    objectname: route.yml

  - role: openshift/object
    app: greenwave
    template: deploymentconfig.yml
    objectname: deploymentconfig.yml
    tags:
      - apply-deploymentconfig

  - role: openshift/rollout
    app: greenwave
    dcname: greenwave-web

  - role: openshift/rollout
    app: greenwave
    dcname: greenwave-fedmsg-consumers

- name: Change the route haproxy default timeout
  hosts: os_control[0]:os_control_stg[0]
  user: root
  gather_facts: False

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
    - name: Set the timeout to the openshift route
      command: "oc -n greenwave annotate route {{ item }} --overwrite haproxy.router.openshift.io/timeout=750s"
      with_items:
        - greenwave-web
        - web-pretty
  tags:
    - route-timeout
